package com.mrd.gtimp.business.entity;

import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.base.entity.User;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity(name = "T_BIZ_FUND_AJUSTMENT")
public class FundAjustment implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * id
     */
    @Id
    @GeneratedValue(generator = "paymentableGenerator")
    @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
    @Column(name = "ID")
    private String id;
    /**
     * 付款编号
     */
    @Column(name = "BID", updatable = false)
    private String bid;

    public String generateBid() {
        return getBidPrefix() + owner.getId().substring(0, 3).toUpperCase()
                + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
                + ((int) (Math.random() * 1000));
    }

    private String getBidPrefix(){
//        if(FundPayTypeEnum.ONLINE.toString().equals(this.fundPayType)){
//            return "CZ";
//        }else if(FundPayTypeEnum.Alipay.toString().equals(this.fundPayType)){
//            return "AZ";
//        }else if(FundPayTypeEnum.WechatPay.toString().equals(this.fundPayType)){
//            return "WZ";
//        }
        return "CZ";
    }

    /**
     * 账户所属公司
     */
    @ManyToOne
    @JoinColumn(updatable = false, name = "COM_ID")
    private Company owner;
    /**
     * 注册人，创建人,充值人
     */
    @ManyToOne
    @JoinColumn(updatable = false, name = "REG_USER_ID")
    private User registrant;
    /**
     * 创建时间，入账时间
     */
    @Column(name = "REG_DATE", updatable = false)
    private Date regDate;
    /**
     * 最后修改人
     */
    @ManyToOne
    @JoinColumn(name = "MODI_USER_ID")
    private User modifier;
    /**
     * 最后修改时间
     */
    @Column(name = "MODI_DATE")
    private Date modiDate;
    /**
     * 当前状态
     */
    @Column(name = "STATE")
    // private FundStateEnum state;
    private String state;

    @ManyToOne
    @JoinColumn(name = "FUNDFLOW_ID")
    private FundFlow fundFlow;
    /**
     * 审核人
     */
    @ManyToOne
    @JoinColumn(name = "REVIEW_USER_ID")
    private User reviewer;
    /**
     * 审核时间
     */
    @Column(name = "REVIEW_DATE")
    private Date reviewDate;

    /**
     * 付款方式
     */
    @Column(name = "FUND_PAY_TYPE")
    // private FundPayTypeEnum fundPayType;
    private String fundPayType;

    @ManyToOne
    /**
     * 如果是付款方式为转账的话，必须上传水单
     */
    @JoinColumn(name = "TRANSFERCERTIFICATE_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Attachment transferCertificate;
    /**
     * 付款金额(元)
     */
    @Column(name = "AMOUNT")
    private double amount;
    /**
     * 在线付款交易单号
     */
    @Column(name = "BILL_NO")
    private String billNo;

    /**
     * 客户水单号
     */
    @Column(name = "SHUIDAN_NO")
    private String shuiDan;

    /**
     * 审核人水单号
     */
    @Column(name = "REVIEW_SHUIDAN_NO")
    private String reviewShuiDan;

    /**
     * 反馈到账状态,已反馈、未反馈
     */
    @Column(name = "FEEDBACK_STATE")
    private String feedbackState;

    /**
     * 反馈时间
     */
    @Column(name = "FEEDBACK_TIME")
    private Date feedbackTime;

    /**
     * 反馈凭证上传
     */
    @Column(name = "FEEDBACK_CERTIFICATE")
    private String feedbackCertificate;

    public String getFeedbackCertificate() {
        return feedbackCertificate;
    }

    public void setFeedbackCertificate(String feedbackCertificate) {
        this.feedbackCertificate = feedbackCertificate;
    }

    public Date getFeedbackTime() {
        return feedbackTime;
    }

    public void setFeedbackTime(Date feedbackTime) {
        this.feedbackTime = feedbackTime;
    }

    public String getFeedbackState() {
        return feedbackState;
    }

    public void setFeedbackState(String feedbackState) {
        this.feedbackState = feedbackState;
    }

    public String getReviewShuiDan() {
        return reviewShuiDan;
    }

    public void setReviewShuiDan(String reviewShuiDan) {
        this.reviewShuiDan = reviewShuiDan;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBid() {
        return bid;
    }

    public void setBid(String bid) {
        this.bid = bid;
    }

    public Company getOwner() {
        return owner;
    }

    public void setOwner(Company reg_company_id) {
        this.owner = reg_company_id;
    }

    public User getRegistrant() {
        return registrant;
    }

    public void setRegistrant(User registrant) {
        this.registrant = registrant;
    }

    public Date getRegDate() {
        return regDate;
    }

    public void setRegDate(Date regDate) {
        this.regDate = regDate;
    }

    public User getModifier() {
        return modifier;
    }

    public void setModifier(User modifier) {
        this.modifier = modifier;
    }

    public Date getModiDate() {
        return modiDate;
    }

    public void setModiDate(Date modiDate) {
        this.modiDate = modiDate;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public FundFlow getFundFlow() {
        return fundFlow;
    }

    public void setFundFlow(FundFlow fundFlow) {
        this.fundFlow = fundFlow;
    }

    public User getReviewer() {
        return reviewer;
    }

    public void setReviewer(User reviewer) {
        this.reviewer = reviewer;
    }

    public Date getReviewDate() {
        return reviewDate;
    }

    public void setReviewDate(Date reviewDate) {
        this.reviewDate = reviewDate;
    }

    public String getFundPayType() {
        return fundPayType;
    }

    public void setFundPayType(String fundPayType) {
        this.fundPayType = fundPayType;
    }

    public Attachment getTransferCertificate() {
        return transferCertificate;
    }

    public void setTransferCertificate(Attachment transferCertificate) {
        this.transferCertificate = transferCertificate;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }


    @Override
    public String toString() {
        return "FundAjustment [id=" + id + ", bid=" + bid + ", reg_company_id=" + owner
                + ", registrant=" + registrant + ", regDate=" + regDate + ", modifier=" + modifier
                + ", modiDate=" + modiDate + ", state=" + state + ", fundFlow=" + fundFlow
                + ", reviewer=" + reviewer + ", reviewDate=" + reviewDate + ", fundPayType="
                + fundPayType + ", transferCertificate=" + transferCertificate + ", amount="
                + amount + ", shuiDan=" + shuiDan + "]";
    }

    public String getBillNo() {
        return billNo;
    }

    public void setBillNo(String billNo) {
        this.billNo = billNo;
    }

    public String getShuiDan() {
        return shuiDan;
    }

    public void setShuiDan(String shuiDan) {
        this.shuiDan = shuiDan;
    }
}
